package leetcode.code2596;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Solution {

	public boolean checkValidGrid(int[][] grid) {
		if (grid[0][0] != 0) {
			return false;
		}
		int n = grid.length;
		int pos[][] = new int[n * n][2];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				pos[grid[i][j]] = new int[] { i, j };
			}
		}

		for (int i = 1; i < n * n; i++) {
			int a = pos[i - 1][0], b = pos[i - 1][1];
			int x = pos[i][0], y = pos[i][1];
			int p = Math.abs(a - x), q = Math.abs(b - y);
			if ((p != 2 || q != 1) && (p != 1 || q != 2)) {

				return false;
			}
		}
		return true;
	}

	public void debug4() {
//		[[0,11,16,5,20],[17,4,19,10,15],[12,1,8,21,6],[3,18,23,14,9],[24,13,2,7,22]]
		int[][] array = new int[][] { { 0, 11, 16, 5, 20 }, { 17, 4, 19, 10, 15 }, { 12, 1, 8, 21, 6 },
				{ 3, 18, 23, 14, 9 }, { 24, 13, 2, 7, 22 } };
		System.out.println("123");
//		System.out.println(String.join(",", ));
		String[] str = Arrays.asList(new Integer[] { 3, 18, 23, 14, 9 }).stream().map(k -> String.valueOf(k))
				.toArray(String[]::new);
		System.out.println(String.join(",", str));
		this.checkValidGrid(array);
	}

	public void debug3() {

	}

	public void debug2() {

	}

	public void debug1() {

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
